package com.boot.ys.mybatisplus.baidu;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

public class BaiduMain {

    // 在平台申请的APP_ID 详见 https://fanyi-api.baidu.com/api/trans/product/desktop?req=developer
    // 文档：https://fanyi-api.baidu.com/doc/21

    public static void main(String[] args) {
        TransApi api = new TransApi("20250607002375929", "dt_fBpLNGD7zfwMwkmcx");

        String query = "学生";
        String transResult = api.getTransResult(query, "zh", "en");
        System.out.println(transResult);
        JSONObject jsonObject = new JSONObject(transResult);
        // 获取dst的值
        String dstValue = jsonObject.getJSONArray("trans_result").getJSONObject(0).getStr("dst");
        System.out.println(dstValue); // 输出: student
    }

}
